const app = getApp();

Page({
  // onShareAppMessage() {
  //   return {
  //     title: "swiper",
  //     path: "page/component/pages/swiper/swiper"
  //   };
  // },
  data: {
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    // 分类类别
    categoryList: [],
    // 商品列表
    productList: [],
    banners:[],
    // 当前页
    curr_page: 1
  },

  onLoad() { 
    let curr_page = this.data.curr_page;
    // this.Fmoney = app.utils.Fmoney;
    this.getCategoryList();
    this.getProductList(curr_page);
    this.getBanners();
  },

  getBanners() {
    let url = '/product/banners';
    app.get(url).then(res=> { 
      this.setData({
        banners: res.data
      })
    })
  },

  toDetail(event) { 
    let id = event.currentTarget.dataset.id; 
    wx.navigateTo({
      url: "/pages/home/detail/detail?id="+id
    });
  },

  onShow() {
    console.log(this.Fmoney);
  },

  getCategoryList() {
    let url = "/category/all";
    app
      .get(url)
      .then(res => {
        this.setData({
          categoryList: res.data
        });
      })
      .catch(err => {
        console.log(err);
      });
  },

  getProductList(curr_page) { 
    let url = "/product/list";
    let data = {
      curr_page
    };
    app
      .get(url, data)
      .then(res => {
        this.setData({
          curr_page: ++curr_page,
          productList: [...this.data.productList,...res.data]
        });
      })
      .catch(err => {
        console.log(err);
      });
  },

 onReachBottom() {
   this.getProductList(this.data.curr_page);
 }

});